﻿#ifndef TRDATAMANAGER_H
#define TRDATAMANAGER_H

#include <QVector>
#include <QObject>
#include "TrTypes.h"

class TrDataManager : public QObject
{
    Q_OBJECT
public:
    TrDataManager(const QString& code, WTSKlinePeriod = KP_DAY);
    double highPrice();
    double lowPrice();
    double highPrice(double drift);
    double lowPrice(double drift);
    double highPrice(int count, int deviation = 0);
    double lowPrice(int count, int deviation = 0);
    double lastPrice();
    uint   lastUpdateTime();
    WTSBarStruct getBar(int i);
    std::vector<WTSBarStruct> getBars();
    unsigned long long size();
private:
    WTSKlinePeriod                  m_KlinePeriod;
    std::vector<uint>               m_vecDatetime;
    std::vector<double>             m_vecOpen;
    std::vector<double>             m_vecHigh;
    std::vector<double>             m_vecLow;
    std::vector<double>             m_vecClose;
    std::vector<int>                m_vecVolume;
    std::vector<WTSBarStruct>       m_vecBars;
    QString                         m_strCode;
    //
    double                          m_dLastPrice;
    uint                            m_uLastUpdate;
    WTSBarStruct                    m_newBar;
    Commodity                       m_Commodity;
public slots:
    void OnTick(CThostFtdcDepthMarketDataField* tick);
    void OnBar(WTSBarStruct bar);
    void OnQuote(char* json, char* period);
signals:
    void OnDataUpdated();
};

#endif // TRDATAMANAGER_H
